package Messages;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import ocsf.server.ConnectionToClient;
import server.SQLConnection;
/**
 * This class implements update vase in  the DB 
 * @author Gabi Revah
 * @author Aviad Almog
 */ 
public class MessageUpdateVase {
	private ConnectionToClient client ;
	private String[] str; 
/**
 * Constructor of this class 
 * @param str
 * @param client
 */

	public MessageUpdateVase(String[] str, ConnectionToClient client){
		
		this.client= client ;
		this.str= str; 	
	
	}
	/**
	 * This method update vase details in the DB
	 * @throws SQLException
	 * @throws IOException
	 */
	public void UpdateVase() throws SQLException, IOException{
		SQLConnection sc = new SQLConnection();
		java.sql.PreparedStatement sid = sc.getConnection().prepareStatement("SELECT * FROM db.vases where name='"+str[1]+"'and color='"+str[2]+"';" );
		ResultSet rss= sid.executeQuery();
		if(rss.next())
		{
		 ArrayList<Object> uv=new ArrayList<Object>();
		 uv.add("UpdateVase");
		 uv.add(rss.getString(1));
		 uv.add(rss.getString(2));
		 uv.add(rss.getInt(3));
		 uv.add(rss.getInt(4));
		 uv.add(rss.getInt(5));
		 uv.add(rss.getInt(6));
	
		 client.sendToClient(uv);
		}
	}

}
